package com.by.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.by.and_widget.ActionSheetDialog;
import com.by.ui.banner.BannerActivity;
import com.by.ui.menu.MenuActivity;
import com.by.ui.recyclerview.RecyclerViewActivity;
import com.by.ui.tag.TagActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        findViewById(R.id.click_tag).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(TagActivity.class);
            }
        });
        findViewById(R.id.click_recycler_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(RecyclerViewActivity.class);
            }
        });
        findViewById(R.id.click_action_sheet).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                testActionSheet();
            }
        });

        findViewById(R.id.click_shape_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(ShapeImageActivity.class);
            }
        });
        findViewById(R.id.click_drag_top).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(DragTopActivity.class);
            }
        });
        findViewById(R.id.click_ptr).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(PtrActivity.class);
            }
        });

        findViewById(R.id.click_menu).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(MenuActivity.class);
            }
        });
        findViewById(R.id.click_banner).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(BannerActivity.class);
            }
        });
        findViewById(R.id.click_nine_grid).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goActivity(NineGridActivity.class);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void goActivity(Class<? extends Activity> clazz) {
        startActivity(new Intent(this, clazz));
    }

    private void testActionSheet() {
        new ActionSheetDialog(this)
                .addMenuItem("意见反馈")
                .addMenuItem("感觉怎么样")
                .addMenuItem("点评一下")
                .show();
    }

}
